home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* */
- /* Source - Round Window.c */
- /* Author - Alexander S. Colwell, Copyright (C) 1988, 1989 */
- /* */
- /* Purpose - This will display a round window using "Debugger" DA */
- /* demostration. */
- /* */
- /* Routine - Main : Main entry point module. */
- /* DoOpen : Open the DA and initialized. */
- /* DoClose : Close the DA and wrap it up. */
- /* DoControl : Process DA control commands. */
- /* DoEvent : Process DA event. */
- /* DoUpdate : Update window. */
- /* DoMouse : Process mouse-down. */
- /* DoKey : Process key inputs. */
- /* DoContent : Process mouse down inside window. */
- /* GetResourceID : Get DA resource ID number. */
- /* */
- /* Revisions - None. */
- /* */
- /********************************************************************/
-
- #include <Color.h> /* Color Manager defs */
- #include <math.h> /* Math defs */
- #include <SetUpA4.h> /* Desk Accessory defs */
- #include <VRetraceMgr.h> /* Vertical Retrace Manager defs*/
- #include "Debugger.h" /* Debugger defs */
-
- /* Misc definitions */
- #define NIL (0L) /* NIL pointer */
- #define abs(a) (a<0?-a:a) /* Absolute macro function */
- #define min(a,b) (a<b?a:b) /* Minumim macro function */
- #define max(a,b) (a<b?b:a) /* Maximum macro function */
-
- /* Resource ID #'s */
- #define windID 0 /* Window ID # */
-
- #define helloWorld "\pHello, World"/* String message */
-
- typedef struct { /* VBL data structure */
- VBLTask vblTask; /* VBL */
- DBGHDL dbgHdl; /* Debugger handler */
- short counter; /* Tick counter */
- } VBL;
- typedef VBL *VBLPTR;
-
- DCtlPtr dce; /* Device control entry */
- WindowPtr wp = NIL; /* My window pointer */
- short alreadyOpen = FALSE;/* 1 -> DA is already open */
- VBLPTR vblPtr = NIL; /* VBL data block */
- Handle vblHdl = NIL; /* VBL code handle */
- DBGHDL dbgHdl = NIL; /* Debugger reference handle */
-
- main(p,d,n)
-
- cntrlParam *p; /* Parameter block */
- DCtlPtr d; /* Device control entry */
- short n; /* Entry point selector */
-
- {
-
- WindowPtr savePort; /* Save current window port */
-
- if (d->dCtlStorage == 0) { /* Check if got the globals 1st!*/
-
- if (n == 0) { /* Check if requesting "Open" */
-
- SysBeep(1); /* Beep da user! */
-
- CloseDriver(d->dCtlRefNum);/* Close the DA */
-
- }
-
- }
-
- else { /* Got the globals then continue*/
-
- GetPort(&savePort); /* Get current window port */
-
- if (wp) /* Check if window ptr valid */
- SetPort(wp); /* Set port to my window */
-
- dce = d; /* Save DCE ptr into our globals*/
-
- dce->dCtlFlags &= ~dCtlEnable;/* Set it not to be re-entrant*/
-
- switch(n) { /* Handle request: */
-
- case 0: /* "Open" */
- DoOpen(); break;
-
- case 2: /* "Control" */
- DoControl(p->csCode,p->csParam); break;
-
- case 4: /* "Close" */
- DoClose(); break;
-
- }
-
- dce->dCtlFlags |= dCtlEnable;/* Enable calls once more */
-
- SetPort(savePort); /* OK, let's restore it */
-
- }
-
- return(0); /* Return default success */
-
- }
-
- DoOpen()
-
- {
-
- Handle wDEFHdl; /* Working window def handle */
-
- /* Add neccesary driver flags */
- dce->dCtlFlags |= dNeedLock|dNeedGoodBye;
-
- if (wp) /* Check if there a window */
- SelectWindow(wp); /* Bring our window front */
-
- if (!alreadyOpen) { /* Check if require inits */
-
- wp = GetNewWindow(GetResourceID(windID),NIL,-1L);
-
- if (wp) { /* Check if got the window */
-
- /* Check if got our WDEF */
- if (wDEFHdl = GetResource('WDEF',GetResourceID(0)))
- ((WindowPeek)(wp))->windowDefProc = wDEFHdl;
-
- ShowWindow(wp); /* Show the window now */
-
- SetPort(wp); /* Set port to our window */
-
- alreadyOpen = TRUE; /* Set open DA indicator */
-
- /* Save window association */
- ((WindowPeek)wp)->windowKind = dce->dCtlRefNum;
-
- dce->dCtlWindow = wp;/* Tell device where I am */
-
- dbgHdl = DbgGetRefHdl();/* Get reference handle */
-
- /* Check if got VBL data pointer*/
- if (vblPtr = (VBLPTR)(NewPtr((long)sizeof(VBL)))) {
-
- /* Check if got VBL code */
- if (vblHdl = GetResource('VBLC',GetResourceID(0))) {
-
- HLock(vblHdl);/* Lock it down for VBL task */
-
- /* Init VBL task */
- vblPtr->vblTask.vblAddr = (ProcPtr)(*vblHdl);
- vblPtr->vblTask.vblCount = 120;
- vblPtr->vblTask.vblPhase = 0;
- vblPtr->vblTask.qType = vType;
- vblPtr->dbgHdl = dbgHdl;
- vblPtr->counter = 120;
-
- VInstall(vblPtr);/* Install the VBL task */
-
- }
-
- }
-
- }
-
- else { /* Fail to open */
-
- SysBeep(1); /* Beep da user! */
-
- CloseDriver(dce->dCtlRefNum);/* OK, let's close DA */
-
- }
-
- }
-
- }
-
- DoClose()
-
- {
-
- if (wp) /* Check if window ptr valid */
- DisposeWindow(wp); /* Delete the window now */
- wp = NIL; /* Invalidate it now */
-
- if (vblPtr && vblHdl) /* Check if VBL task is installed*/
- VRemove(vblPtr);
-
- if (vblPtr) /* Check if has VBL data pointer*/
- DisposPtr(vblPtr); /* Release it now */
- vblPtr = NIL; /* Invalidate it now */
-
- if (vblHdl) { /* Check if has VBL code handle */
- HUnlock(vblHdl); /* OK, it's safe to unlock it */
- ReleaseResource(vblHdl);/* Release it now */
- }
- vblHdl = NIL; /* Invalidate it now */
-
- alreadyOpen = FALSE; /* Reset it (really doesn't matter)*/
-
- }
-
- DoControl(code,parm)
-
- short code; /* Control command code */
- short *parm; /* "csParam" list pointer */
-
- {
-
- switch(code) { /* Handle request: */
-
- case accEvent: /* "Event" */
- DoEvent(*((EventRecord **)parm)); break;
-
- case goodBye: /* "GoodBye" */
- DoClose(); break;
-
- }
-
- }
-
- DoEvent(e)
-
- register EventRecord *e; /* Event Record pointer */
-
- {
-
- /* Output DA's event type */
- DbgPrint(dbgHdl,"DA Event: what - %d\n",e->what);
-
- switch(e->what) { /* Handle request: */
-
- case updateEvt: /* "Update" */
- DoUpdate(); break;
-
- case mouseDown: /* "Mouse Down" */
- DoMouse(e->where,e->modifiers); break;
-
- case keyDown: /* "Key Down" */
- case autoKey: /* "Auto-Key Down" */
-
- /* Handle the input key */
- DoKey((char)(e->message & charCodeMask),
- (char)((e->message & keyCodeMask) >> 8L),
- e->modifiers);
-
- }
-
- }
-
- DoUpdate()
-
- {
-
- BeginUpdate(wp); /* Start update processing */
-
- EraseRect(&wp->portRect); /* Clear the window */
-
- MoveTo(abs(wp->portRect.right - wp->portRect.left) / 2 -
- StringWidth(helloWorld) / 2,
- abs(wp->portRect.bottom - wp->portRect.top) / 2);
-
- DrawString(helloWorld); /* Draw the string message */
-
- EndUpdate(wp); /* Wrapup update processing */
-
- }
-
- DoMouse(p,modifiers)
-
- Point p; /* Mouse point position */
- short modifiers; /* Mouse's modifiers */
-
- {
-
- register long i; /* Working index */
- Rect wRect; /* Working window rect area */
- register long wGrow; /* Working grow size */
- ProcPtr wDef; /* Working window proc hdl */
-
- /* Load it into memory */
- LoadResource(((WindowPeek)wp)->windowDefProc);
-
- HLock(((WindowPeek)wp)->windowDefProc);/* Lock it down */
-
- /* Get window proc definition */
- wDef = (ProcPtr)*((WindowPeek)wp)->windowDefProc;
-
- /* Check if in "Content" */
- if (CallPascalL(8,wp,(int)wHit,p,wDef) == wInContent)
- DoContent(p,modifiers);
-
- HUnlock(((WindowPeek)wp)->windowDefProc);/* OK, unlock it down*/
-
- }
-
- DoKey(c,code,modifiers)
-
- char c; /* Input character */
- char code; /* Input code */
- short modifiers; /* Input modifiers */
-
- {
-
- if (modifiers & cmdKey) { /* Check if key command */
-
- if (c == 'q') /* Check if time to quit */
- CloseDriver(dce->dCtlRefNum);/* OK, let's close DA */
-
- else /* Opps, invalid command */
- SysBeep(1); /* Let the user know about it */
-
- }
-
- }
-
- DoContent(p,modifiers)
-
- Point p; /* Mouse down point */
- short modifiers; /* Mouse's modifiers */
-
- {
-
- Rect wRect; /* Working window rect area */
- register long wGrow; /* Working grow point */
- WindowPtr wPtr; /* Working window pointer */
-
- /* Check if want to resize it */
- if (modifiers & (shiftKey | optionKey | cmdKey)) {
-
- SetRect(&wRect,50,50,32767,32767);/* Define the limits */
-
- wGrow = GrowWindow(wp,p,&wRect);/* OK, let's grow it now*/
-
- if (wGrow) { /* Check if specified new size */
-
- /* Reset new size */
- SizeWindow(wp,LoWord(wGrow),HiWord(wGrow),TRUE);
-
- InvalRect(&wp->portRect);/* Invalidate everything */
-
- }
-
- }
-
- else { /* Nope, just move it */
-
- GetWMgrPort(&wPtr); /* Get window manager pointer */
-
- DragWindow(wp,p,&wPtr->portRect);/* Drag the window */
-
- }
-
- }
-
- GetResourceID(n) { return(0xC000 + ((~(dce->dCtlRefNum))<<5) + n); }
-